package com.ruoyi.ftrl.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ftrl.domain.BuildingInfo;
import com.ruoyi.ftrl.domain.HeatStation;
import com.ruoyi.ftrl.service.IHeatStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 换热站信息Controller
 * 
 * @author dihang
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/ftrl/station")
public class HeatStationController extends BaseController
{
    @Autowired
    private IHeatStationService heatStationService;

    /**
     * 根据片区id查询子级热力站
     */
    @GetMapping(value = "/heat/{id}")
    public TableDataInfo getInfos(@PathVariable("id") Long id)
    {
        List<HeatStation> heatStations = heatStationService.selectHeatStationLists(id);
        return getDataTable(heatStations) ;
    }

    /**
     * 查询换热站信息列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(HeatStation heatStation)
    {
//        startPage();
        List<HeatStation> list = heatStationService.selectHeatStationList(heatStation);
        return getDataTable(list);
    }

    /**
     * 导出换热站信息列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:station:export')")
    @Log(title = "换热站信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HeatStation heatStation)
    {
        List<HeatStation> list = heatStationService.selectHeatStationList(heatStation);
        ExcelUtil<HeatStation> util = new ExcelUtil<HeatStation>(HeatStation.class);
        util.exportExcel(response, list, "换热站信息数据");
    }

    /**
     * 获取换热站信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:station:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(heatStationService.selectHeatStationById(id));
    }

    /**
     * 新增换热站信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:station:add')")
    @Log(title = "换热站信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HeatStation heatStation)
    {
        return toAjax(heatStationService.insertHeatStation(heatStation));
    }

    /**
     * 修改换热站信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:station:edit')")
    @Log(title = "换热站信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeatStation heatStation)
    {
        return toAjax(heatStationService.updateHeatStation(heatStation));
    }

    /**
     * 删除换热站信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:station:remove')")
    @Log(title = "换热站信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(heatStationService.deleteHeatStationByIds(ids));
    }
}
